from appium.webdriver.common.mobileby import MobileBy
from selenium.webdriver.support import expected_conditions
from selenium.webdriver.support.wait import WebDriverWait

from APPauto.test_APPauto_practice.test_enterprise_wechat_app.po_add_del_member.package.base import Base


class AddMemberPackage(Base):

    def non_auto_add_member(self):
        """'手动添加成员"""
        # 填入成员信息
        self.driver.find_element(MobileBy.XPATH,"//*[contains(@text,'手动输入')]").click()
        WebDriverWait(self.driver,10).until(
            expected_conditions.presence_of_element_located((MobileBy.XPATH,"//*[@text='必填']")))
        self.driver.find_element(MobileBy.XPATH,"//*[@text='必填']").send_keys("成员01")
        self.driver.find_element(MobileBy.XPATH, "//*[@text='手机号']").send_keys("12345678901")
        # 添加邮箱，注意页面有两个【选填】，找出class不同后使用 and 联合定位，这里用路径不好区分
        self.driver.find_element(MobileBy.XPATH, "//*[@text='选填' and @class='android.widget.EditText']").send_keys("58947458885@qq.com")
        # 取消发送邀请通知
        self.driver.find_element(MobileBy.XPATH, "//*[@text='保存后自动发送邀请通知']").click()
        # 保存
        self.driver.find_element(MobileBy.XPATH, "//*[@text='保存']").click()

    def verify_ok(self):
        """断言：添加成功"""
        # 断言 这里时toast控件，使用Xpath，不用 assert '添加成功' in self.driver.page_source 进行断言
        self.driver.find_element(MobileBy.XPATH, "//*[@text='添加成功']")
